<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%String skin = (String) session.getAttribute("USERSKIN_SESSION");%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <%--<meta name="viewport" content="width=device-width, initial-scale=1.0" />--%>
    <title>陕西省车驾管业务电子缴费系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
 <%--   <jsp:include page="/inc/head.jsp" flush="true"/>
    <jsp:include page="/inc/footer.jsp" flush="true"/>--%>
   <%-- <script src="${basePath}/js/bootstrap-treeview/js/bootstrap-treeview.js"></script>--%>
<style type="text/css">
    *{
        margin:0;
        padding:0
    }
    #addUserTable tr{
        width: 100%;
        height: 10%;
    }
    #addUserTable td{
        font-size: 14px;
        width:80px;
        height:40px;
    }

    #addUserTable .content{
        padding-left: 20px;
    }

    #addUserTable select{
        width:300px;
    }
    #addUserTable input{
        border: 1px solid #AAAAAA;
        border-radius: 3px;
        height:30px;
    }
</style>

</head>
<body class="hold-transition skin-blue sidebar-mini" >
<div class="container" >
    <div id="AddUserModal" class="modal fade bs-example-modal-lg addUpdateInfo" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog " role="document" >
            <div class="modal-content" style="width: 900px;height: 700px">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel" >添加用户/编辑用户</h4>
                </div>
                <div class="modal-body" >
                    <form id="volumeForm" class="form-horizontal form-bordered form-row-strippe" method="post">
                        <table style="width:100%;height: 450px" id="addUserTable">
                            <tr >
                                <td width='300px' height='40px' style='padding-left: 15px;'>账户信息：</td>
                            </tr>
                            <tr >
                                <td width='300px' height='40px' style='padding-left: 15px;'>用户名：</td>
                                <td>
                                    <input class="text" type='text' id='userName' name='userName' placeholder="必填项" value=''>
                                </td>
                                <td id="usernameError" height="35"  class="content" style="display:none">
                                    <font color="red" size="-1">用户名只能为数字或英文字母</font>
                                </td>
                            </tr>
                            <tr >
                                <td width='300px' height='40px' style='padding-left: 15px;'>密码：</td>
                                <td>
                                    <input class="text" id='password' name='password' placeholder="必填项" value='' type="text">
                                </td>
                                <td id="userpasswordError" height="35"  class="content" style="display:none">
                                    <font color="red" size="-1">密码需大于6位,且只能为数字或英文字母</font>
                                </td>
                            </tr>
                            <tr >
                                <td width='300px' height='40px' style='padding-left: 15px;'>确认密码：</td>
                                <td>
                                    <input class="text" id='repassword' name='repassword' placeholder="必填项" value='' type="text">
                                </td>
                                <td id="userpassword1Error" height="35" class="content" style="display:none">
                                    <font color="red" size="-1">两次密码不一致</font>
                                </td>
                            </tr>
                            <tr >
                                <td width='300px' height='40px' style='padding-left: 15px;'>管理员信息：</td>
                            </tr>
                            <tr >
                                <td width='300px' height='40px' style='padding-left: 15px;'>管理员姓名：</td>
                                <td>
                                    <input class="text" type='text' id='userPeName' name='userPeName' placeholder="必填项" value=''>
                                </td>
                            </tr>
                            <tr >
                                <td width='300px' height='40px' style='padding-left: 15px;'>身份证号码：</td>
                                <td>
                                    <input class="text" type='text' id='userIdCode' name='userIdCode' placeholder="必填项" value=''>
                                </td>
                            </tr>
                            <tr >
                                <td width='300px' height='40px' style='padding-left: 15px;'>数据范围选择：</td>
                                <td width='300px'style="font-size: 14px; font-family: Tahoma;"><input id="allManager" type="checkbox" style='padding-left: 15px;vertical-align:middle; margin-top:0;' value="0">&nbsp&nbsp陕西总队</td>
                            </tr>
                            <tr>
                                <td width='300px' height='40px' style='padding-left: 15px;'></td>
                                <td>
                                    <select  class="form-control" id="addParentManList" onchange="checkParentManager()">
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td width='300px' height='40px' style='padding-left: 15px;'></td>
                                <td>
                                    <select  class="form-control" id="addVehicleList" >
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td width='300px' height='40px' style='padding-left: 15px;'>状态：</td>
                                <td>
                                    <input id="userStatus" name="status" type="checkbox" height='50px' value="0">
                                </td>
                            </tr>
                            <tr >
                                <td width='300px' height='40px' style='padding-left: 15px;'>角色选择：</td>
                                <td>
                                    <select  class="form-control" id="addRoleList">
                                        <option>--请选择角色--</option>
                                    </select>
                                </td>
                            </tr>
                        </table>
                    </form>

            </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" onclick="addUserAction()" class="btn btn-primary">确认修改</button>
                </div>
        </div>
    </div>

</div>
</div>
<script>
        //校验用户
        //用户校验
        $("#userName").focus(function() {
            $("#userName").css("background-color", "#DCE9F5");
        });
        $("#userName").blur(function(){
            var username = $("#userName").val();
            $("#assword").css("background-color", "white");
            var re;
            re =  /^[\da-z]+$/;
            if (re.test(username)) {
                $("#usernameError").hide();
            }else{
                $("#usernameError").show();
            }
        });
        //password验证
        $("#password").focus(function() {
            $("#password").css("background-color", "#DCE9F5");
        });
        $("#password").blur(function(){
            var upassword = $("#password").val();
            $("#assword").css("background-color", "white");
            if (upassword.length >= 6 ) {
                var re;
                re =  /^[\da-z]+$/;
                if (re.test(upassword)) {
                    $("#userpasswordError").hide();
                }else{
                    $("#userpasswordError").show();
                }
            } else {
                $("#userpasswordError").show();
            }

        });
        //password1验证
        $("#repassword").focus(function() {
            $("#repassword").css("background-color", "#DCE9F5");
        });
        $("#repassword").blur(function(){
            var password = $("#password").val();
            var repassword = $("#repassword").val();
            $("#repassword").css("background-color", "white");
            if (repassword != password) {
                $("#userpassword1Error").show();
            } else {
                $("#userpassword1Error").hide();
            }
        });
    function checkParentManager(){
    var addParentManList=$("#addParentManList").find(":selected").val();
    $.ajax({
        type: "POST",
        url: "/pcwindow/findVehcicleManageByParent",
        dataType: "json",
        data:{ mdId : addParentManList },
        async:false,
        success: function (data) {
            if (data.length != 0) {
                var ManagerDepartment = data;
                $("#addVehicleList").find("option").remove();
                var str =  '<option value="0">请选择管理部门信息</option>';
                for (var i = 0; i < ManagerDepartment.length; i++) {
                    var mdName = ManagerDepartment[i].mdName;
                    var mdCode = ManagerDepartment[i].mdCode;
                    str += '<option value="' + mdCode + '">' + mdName + '</option>'
                }
                $('#addVehicleList').html(str);
            }
        }
    })
}
function addUserAction() {
    debugger
    var userId=$("#userId").val();
    var userName=$("#userName").val();
    var password=$("#password").val();
    var repassword=$("#repassword").val();
    var userPeName=$("#userPeName").val();
    var userIdCode=$("#userIdCode").val();
    var userStatus= $('[name="status"]').val();
    var addRoleList=$("#addRoleList").find(":selected").val();
    var addParentManList=$("#addParentManList").find(":selected").val();
    var addVehicleList=$("#addVehicleList").find(":selected").val();
    var sign ;
    var mdCode;
    if(userId == ""){
        sign =0;
    }else{
        sign =1;
    }
    if($('#allManager').is(':checked')){
        mdCode = "61";
    }else{
        if(addVehicleList != 0) {
            mdCode = addVehicleList;
        }else{
            mdCode = addParentManList;
        }
    }
    if(userName == ""){
        alert("用户名不能为空");
    }else if(password == ""||password.length < 6){
        alert("密码格式不正确");
    }else if(repassword == ""||repassword != password){
        alert("确认密码格式不正确");
    }else if(addRoleList == ""){
        alert("请选择角色");
    }else if(mdCode == "" || mdCode == 0){
        alert("请选择数据范围");
    }else{
        $.ajax({
            type: "POST",
            url: "/pcwindow/userManager",
            dataType: "json",
            data:{
                flag : sign,
                userName : userName ,
                password : password ,
                userStatus : userStatus ,
                roleId : addRoleList ,
                mdCode : mdCode,
                userId :userId,
                userPeName : userPeName,
                userIdCode : userIdCode
            },
            async:false,
            success: function (data) {
                if (data.status == 200) {
                    if(sign != 0){
                        alert("编辑用户的申请已提交，等待总队审核");
                        $('#AddUserModal').modal("hide")
                        $("#userId").val("");
                        $("#table").bootstrapTable('refresh');
                    }else{
                        alert("添加用户的申请已提交，等待总队审核");
                        $('#AddUserModal').modal("hide")
                        $("#table").bootstrapTable('refresh');
                    }

                }
            }
        });
    }
 }
function userMessageShow(userId) {
    //var rows = $table.bootstrapTable('getSelections');
        $("#userId").val(userId);
        $.ajax({
            type: "POST",
            url: "/pcwindow/findUserByUserId",
            dataType: "json",
            data:{
                userId : userId,
            },
            async:false,
            success: function (data) {
                if (data.length != 0) {
                    $("#userName").val(data.user_name);
                    $("#password").val("* * * * * *");
                    $("#repassword").val("* * * * * *");
                    $("#userPeName").val(data[0].user_pename);
                    $("#userIdCode").val(data[0].user_idcode);
                    if(data[0].user_status == 1){
                        $('[name="status"]').bootstrapSwitch('state',true);
                    }else{
                       $('[name="status"]').bootstrapSwitch('state',false);
                    }
                    $("#addRoleList option[value='"+data[0].ro_id+"']").attr("selected","selected");
                    if(data[0].md_rank == "1"){
                        $("#allManager").prop('checked',true);
                    }else if(data[0].md_rank == "2"){
                        $("#addParentManList option[value='"+data[0].user_orgcode+"']").attr("selected","selected");
                    }else{
                        $("#addVehicleList option[value='"+data[0].user_orgcode+"']").attr("selected","selected");
                    }
                    $('#AddUserModal').modal("show");
                }
            }
        });
}
</script>
</body>
</html>

